//监听浏览器页面是刷新还是关闭的hook
const usePageRefresh = (func) => {
    //开始时间
    let beginTime = 0;
    //时间差
    let differTime = 0;
    addEventListener("beforeunload", () => {
        beginTime = new Date().getTime();
    })

    addEventListener("unload", () => {
        differTime = new Date().getTime() - beginTime;
        if (differTime <= 5) {
            if (func) func("close")
        } else {
            if (func) func("refresh")
        }
    })
}

export default usePageRefresh